/***************************************************************************

-------------------
    begin                : 
    copyright            : kuzkok
    email                : kuzkok at gmail.com

***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*   
*   Данная программа является свободным программным обеспечением;         *
*   Вы можете распространять ее и/или модифицировать в соответствии с     *
*   GNU General Public License опубликованной Фондом свободного           *
*   программного обеспечения; используемая версия лицензии - 2 или        *
*   (по вашему выбору) любая более поздняя                                *
***************************************************************************/

#include "fitting.h"

Fitting::Fitting(QString tableName) :
        OnlinePointFacility(tableName)
{
}

Fitting::Fitting(QUuid theEventID, QString tableName) :
        OnlinePointFacility(theEventID, tableName)
{
    if(mObjectState)
    {
        mDateManufactured = mSelectQuery->value(mSelectQuery->record().indexOf("datemanufactured")).toDate();
        mGrade = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("grade")).toString());
        mInletConnectionType = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("inletconnectiontype")).toString());
        mManufacturer = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("manufactured")).toString());
        mMaterial = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("material")).toString());
        mPressureRating = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("pressurerating")).toString());
        mSpecification = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("specification")).toString());
        mInletDiameter = mSelectQuery->value(mSelectQuery->record().indexOf("inletdiameter")).toDouble();
        mInletWallThikness = mSelectQuery->value(mSelectQuery->record().indexOf("inletwallthikness")).toDouble();
    }

}

void Fitting::buildInsertStatement()
{
    OnlinePointFacility::buildInsertStatement();
    mInsertStatementFields += ", datemanufactured"
                             ", grade"
                             ", inletconnectiontype"
                             ", manufacturer"
                             ", material"
                             ", pressurerating"
                             ", specification"
                             ", inletdiameter"
                             ", inletwallthikness";
    mInsertStatementValues += ", :datemanufactured"
                             ", :grade"
                             ", :inletconnectiontype"
                             ", :manufacturer"
                             ", :material"
                             ", :pressurerating"
                             ", :specification"
                             ", :inletdiameter"
                             ", :inletwallthikness";
}

void Fitting::buildUpdateStatement()
{
    OnlinePointFacility::buildUpdateStatement();
    mUpdateStatement += ", datemanufactured = :datemanufactured"
                       ", grade = :grade"
                       ", inletconnectiontype = :inletconnectiontype"
                       ", manufacturer = :manufacturer"
                       ", material = :material"
                       ", pressurerating = :pressurerating"
                       ", specification = :specification"
                       ", inletdiameter = :inletdiameter"
                       ", inletwallthikness = :inletwallthikness";
}

void Fitting::bindQueryValues(QSqlQuery &query)
{
    OnlinePointFacility::bindQueryValues(query);
    query.bindValue(":datemanufactured", mDateManufactured);
    query.bindValue(":grade", UuidToVariant(mGrade));
    query.bindValue(":inletconnectiontype", UuidToVariant(mInletConnectionType));
    query.bindValue(":manufacturer", UuidToVariant(mManufacturer));
    query.bindValue(":material", UuidToVariant(mMaterial));
    query.bindValue(":pressurerating", UuidToVariant(mPressureRating));
    query.bindValue(":specification", UuidToVariant(mSpecification));
    query.bindValue(":inletdiameter", mInletDiameter);
    query.bindValue(":inletwallthikness", mInletWallThikness);
}
